﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MessageSystem.Default.infrastructure
{
    public class list_msg
    {
        public msg head;
        public msg tail;
        public int count;

        public void clear()
        {
            head = tail = null;
            count = 0;
        }

        public void add_tail(msg value)
        {
            value.next = null;
            if (null == head)
            {
                head = value;
                tail = head;
            }
            else
            {
                tail.next = value;
                tail = value;
            }
            ++count;
        }

        public void add_head(msg value)
        {
            value.next = null;
            if (null == head)
            {
                head = value;
                tail = head;
            }
            else
            {
                value.next = head;
                head = value;
            }
            ++count;
        }

        public msg get()
        {
            msg ret = null;
            if (head != null)
            {
                msg next = head.next;
                ret = head;
                ret.next = null;
                head = next;
                if (--count == 0)
                    tail = null;
            }
            return ret;
        }
    }

    class list_block
    {
        public block head;
        public block tail;
        public int count;

        public void clear()
        {
            head = tail = null;
            count = 0;
        }

        public void add_tail(block value)
        {
            value.next = null;
            if (null == head)
            {
                head = value;
                tail = head;
            }
            else
            {
                tail.next = value;
                tail = value;
            }
            ++count;
        }

        public void add_head(block value)
        {
            value.next = null;
            if (null == head)
            {
                head = value;
                tail = head;
            }
            else
            {
                value.next = head;
                head = value;
            }
            ++count;
        }

        public block get()
        {
            block ret = null;
            if (head != null)
            {
                block next = head.next;
                ret = head;
                ret.next = null;
                head = next;
                if (--count == 0)
                    tail = null;
            }
            return ret;
        }
    }
}
